package com.ap.core.validation.message.rules;

import com.ap.core.cxf.jaxb.common.ActivationStatus;
import com.ap.core.dao.MerchantDistributorDetailsDao;
import com.ap.core.domain.MerchantDistributorDetails;
import com.ap.core.domain.MerchantDistributorDetailsId;
import com.ap.core.validation.message.info.MessageValidationInfo;
import com.ap.core.validation.rules.AbstractValidationRule;

public abstract class AbstractMerchantDistributorCheckRule<T, OI> extends AbstractValidationRule<MessageValidationInfo<T, OI>> {

	/**
	 * Merchant Distributor Details Dao.
	 */
	private MerchantDistributorDetailsDao merchantDistributorDetailsDao;

	protected boolean isMerchantAssociatedWithDistributor(
			MerchantDistributorDetailsId merchantDistributorDetailsId) {
		final MerchantDistributorDetails merchantDistributorDetails = merchantDistributorDetailsDao.findById(merchantDistributorDetailsId);
		return null != merchantDistributorDetails;
	}

	protected boolean isMerchantAssociatedWithDistributorInGivenState(MerchantDistributorDetailsId merchantDistributorDetailsId,	ActivationStatus activationStatus) {
		boolean pass = true;
		final MerchantDistributorDetails merchantDistributorDetails = merchantDistributorDetailsDao.findById(merchantDistributorDetailsId);		
		if(null != merchantDistributorDetails){
			pass = activationStatus.equals(merchantDistributorDetails.getMerchantActivationStatus());
		}
		return pass;
	}
	
	abstract public boolean validate(MessageValidationInfo<T, OI> infoObject);

	/**
	 * @param merchantDistributorDetailsDao
	 *            the merchantDistributorDetailsDao to set
	 */
	public void setMerchantDistributorDetailsDao(
			MerchantDistributorDetailsDao merchantDistributorDetailsDao) {
		this.merchantDistributorDetailsDao = merchantDistributorDetailsDao;
	}

}
